<template>
  <el-dialog title="分配角色" :visible="showRoleDialog" @close="handleClose">
    <el-checkbox-group v-model="checkList">
      <el-checkbox v-for="item in roleList" :key="item.id" :label="item.id">{{ item.name }}</el-checkbox>
    </el-checkbox-group>
    <el-button type="primary" @click="submit">确定</el-button>
    <el-button>取消</el-button>
  </el-dialog>
</template>

<script>
import { assignRoles, getEnabledRole, getRoleInfo } from '@/api/role'
export default {

  props: {
    showRoleDialog: {
      type: Boolean,
      required: true
    },
    currentId: {
      type: Number,
      required: true
    }
  },
  data() {
    return {
      checkList: [],
      roleList: []
    }
  },
  created() {
    this.getRoleList()
  },
  methods: {
    handleClose() {
      this.$emit('update:showRoleDialog', false)
    },
    async getRoleList() {
      const res = await getEnabledRole()
      console.log(res)
      this.roleList = res.data
    },
    async getRoleById() {
      const res = await getRoleInfo(this.currentId)
      console.log(res)
      this.checkList = res.data.roleIds
    },
    async submit() {
      const res = await assignRoles({ id: this.currentId, roleIds: this.checkList })
      console.log(res)
      this.$message.success('分配角色成功')
      this.handleClose()
    }
  }
}
</script>

<style>

</style>
